cmake_minimum_required( VERSION 2.8 )

#adapted from http://stackoverflow.com/questions/3065220/ctest-with-multiple-commands

macro( test_dmi_level CMD DMI_FILE )
  execute_process( COMMAND ${CMAKE_COMMAND} -E copy ${DMI_FILE} junk1 ) #copy the file to junk1
  execute_process( COMMAND ${CMD} junk1                  #this runs the command
                  RESULT_VARIABLE CMD_RESULT)
  if(CMD_RESULT)
      message(FATAL_ERROR "Error running ${CMD} on ${DMI_FILE}")
  else()
    #the input file is now junk1.back, and junk1 is the output
    #compare input and output. they should match
    execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files junk1 junk1.back
                      RESULT_VARIABLE CMP_RESULT)
    if(CMP_RESULT)
        message(FATAL_ERROR "checkLevels - cycle test failed on ${DMI_FILE}")
    else()
      #delete temp files
      execute_process( COMMAND ${CMAKE_COMMAND} -E remove junk1 junk1.back )
    endif()
  endif()
endmacro()

test_dmi_level( ${EXE} ${DMI} )
